<template>
	<el-main>
		<el-card shadow="never" v-loading="isLoading">
			<el-form :model="form" ref="form" :rules="rules" label-width="110" :disabled="this.action == 'view'">
				<el-header>
					<h2>问诊设置</h2>
				</el-header>
				<el-main>
					<el-row>
						<el-col :span="11">
							<el-form-item label="免责提示" prop="hehuan_patient_pop" label-width="150">
								<el-radio-group v-model="form.hehuan_patient_pop">
									<el-radio :label="0">永久</el-radio>
									<el-radio :label="1">首次</el-radio>
									<el-radio :label="2">关闭</el-radio>
								</el-radio-group>
							</el-form-item>
						</el-col>
					</el-row>
					<el-col :span="11">
						<div class="el-upload__tip" style="margin-left:150px;">
								<span class="color">
								用户在app点击问诊时免责提示通知配置开关，仅限于和缓视频问诊服务会出现此提示；</span>
						</div>
					</el-col>
				</el-main>
				<el-row>
					<el-col :span="2">
						<el-form-item>
							<el-button type="primary" :loading="isSaveing" @click="submit()">保存</el-button>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
		</el-card>
	</el-main>
</template>
<script>

export default {
	name: 'config_store',
	components: {},
	data() {
		return {
			isSaveing: false,
			form: {
				hehuan_patient_pop: 0
			},
			//验证规则
			rules: {
				hehuan_patient_pop: [
					{required: true, message: '请选择免责提示', trigger: 'change'}
				]
			}
		}
	},
	mounted() {
		//获取信息
		this.loadInfo()
	},
	methods: {
		loadInfo() {
			this.$API['sys.config'].info.get({'config_item':'hehuan_patient_pop'}).then((res) => {
				if (res.code == 0) {
					this.setData(res.data);
				}
			}).catch((msg) => {
				this.$alert(msg, "提示", {type: 'error'})
			})
		},
		submit() {
			this.$refs.form.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					this.form.config_item = 'hehuan_patient_pop';
					this.form.config_val = this.form.hehuan_patient_pop;
					this.$API['sys.config'].store.post(this.form)
						.then((res) => {
							if (res.code == 0) {
								this.$emit('success', this.form, this.mode)
								this.$refs.form.resetFields()
								this.$message.success("操作成功")
							} else {
								this.$alert(res.message, "提示", {type: 'error'})
							}
						})
						.catch((msg) => {
							this.$alert(msg, "提示", {type: 'error'})
						})
						.finally(() => {
							this.isSaveing = false;
							this.setData({'config_val':this.form.config_val});
						});
				} else {
					return false;
				}
			})
		},
		downloadFailedData() {
			window.open(this.failedDownLoadUrl);
		},
		//表单注入数据
		setData(data) {
			this.form.hehuan_patient_pop = parseInt(data.config_val);
		}
	}
}
</script>

<style>
</style>
